package com.riber.student.web.controller;

import com.riber.student.common.Const;
import com.riber.student.common.ResponseResult;
import com.riber.student.entity.RcStudent;
import com.riber.student.service.IRcSystemService;
import com.riber.student.util.TokenUtils;
import com.riber.student.vo.input.LoginInputVo;
import com.riber.student.vo.output.LoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author: Riber
 * @date: 2022/10/25 22:47
 * @description:
 */
public class SystemController {
    @Autowired
    private IRcSystemService systemService;

    @RequestMapping("/login")
    public ResponseResult doLogin(LoginInputVo inputVo, HttpSession session){
        ResponseResult responseResult = systemService.doLogin(inputVo);
        //保存数据到session
        LoginInfoVo data = (LoginInfoVo) responseResult.getData();
        //登出登录状态
        session.setAttribute("is_login", data);
        //登录数据 ResponseResult 里面的data数据线进行jwt解码,重新设置回data
        //把编译好的token令牌数据重新覆盖原有的明文数据
        String token = TokenUtils.getToken(data, Const.HAFT_HOUR);
        responseResult.setData(token);
        return responseResult;
    }
}
